import { Table,  } from 'antd';
import axios from 'axios';
import { useEffect, useState } from 'react';
const columns = [
  {
    title: 'id',
    dataIndex: '_id',
    key:'_id'
  },
  {
    title: '名字',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '成绩',
    dataIndex: 'score',
    key:'score'
  },
  {
    title: '班级',
    dataIndex: 'classId',
    key: 'classId'
  },
  
];

const UserList = () => {
  const [data, setData] = useState([])
  const [key, setKey] = useState(0)
  
   useEffect(() => {
    
    axios.get("/api/allStudents").then((data) => {
      if(data.status == 200) {
        // console.log(data.data);
        setData(data.data)
        data.data.map((item: any) => setKey(item._id))
      }
    },)
  },[setData])
  return (
    <div>
      <div>
      <Table
        columns={columns}
        dataSource={data} 
        key = {key}
      />
    </div>
    </div>
  )
}

export default UserList;